<?php

declare(strict_types=1);
namespace App\Common\Logic;


class CommonLogic
{

    private $menu = [];
    /**
     * 三级展示分层
     * @param $menu
     * @param int $id
     * @param int $level
     * @return array
     */
    public function taglist($menu,$id=0,$level=0){
        foreach ($menu as $value) {
            if ($value['pid']==$id) {
                $value['level'] = $level+1;
                if($level == 0)
                {
                    $value['str'] = str_repeat('',$value['level']);
                }
                elseif($level == 2)
                {
                    $value['str'] = '&emsp;&emsp;'.'└ ';
                    $value['str'] = html_entity_decode($value['str']);
                }
                elseif($level == 3)
                {
                    $value['str'] = '&emsp;&emsp;&emsp;&emsp;'.'└ ';
                    $value['str'] = html_entity_decode($value['str']);
                }
                elseif($level == 4)
                {
                    $value['str'] = '&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;'.'└ ';
                    $value['str'] = html_entity_decode($value['str']);
                }
                else
                {
                    $value['str'] = '&emsp;&emsp;'.'└ ';
                    $value['str'] = html_entity_decode($value['str']);
                }
                $this->menus[] = $value;
                $this->taglist($menu,$value['id'],$value['level']);
            }
        }
        return $this->menus;
    }

}
